package edu.ccut.saturn.component.impl.node;

import edu.ccut.saturn.component.ComponentManager;
import edu.ccut.saturn.component.ILogicContext;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.loader.node.EndNodeInfoLoader;
import edu.ccut.saturn.component.loader.node.NodeInfoLoader;
import edu.ccut.saturn.component.xml.ISaturnElement;
import edu.ccut.saturn.component.xml.SaturnElement;

/**
 * 结束结点的实现类。在logic组件中被调用，表示流程运行结束。 <code>EndNodeInfo</code>继承了<code>AbstractNodeInfo</code>。
 * 
 * @author 谷钰
 * 
 * @version 1.0 2008.8.19
 */
public class EndNodeInfo extends AbstractNodeInfo {

	public EndNodeInfo(String id, String name, String description, String x,
			String y) {

		super(id, name, description, null, null, x, y, "end");
	}

	@Override
	public void doExecute(ILogicContext logicContext) throws Exception {
		ComponentManager.beforeExecuteComponent(this, null);
		ComponentManager.afterExecuteComponent(this, null);
	}

	@Override
	protected IParameterContext createParameterContext(
			ILogicContext logicContext) throws Exception {

		return null;
	}

	public ISaturnElement toSaturnElement() {
		ISaturnElement endElement = new SaturnElement(
				EndNodeInfoLoader.KEY_NODETYPE_END);

		endElement.addAttribute(NodeInfoLoader.KEY_NODE_ID, this.getId());
		endElement.addAttribute(NodeInfoLoader.KEY_NODE_NEXT, this.getNextId());
		endElement.addAttribute(NodeInfoLoader.KEY_NODE_X, this.getX());
		endElement.addAttribute(NodeInfoLoader.KEY_NODE_Y, this.getY());

		ISaturnElement nameElement = new SaturnElement(
				NodeInfoLoader.KEY_NODE_NAME, this.getName());

		ISaturnElement parametersElement = new SaturnElement(
				NodeInfoLoader.KEY_PARAMETER_LIST);

		ISaturnElement descriptionElement = new SaturnElement(
				NodeInfoLoader.KEY_NODE_DESCRIPTION, this.getDescription());

		endElement.addSubElement(nameElement);
		endElement.addSubElement(parametersElement);
		endElement.addSubElement(descriptionElement);
		return endElement;
	}

}
